<?php
$_upcoming = true;
include $this->getTemplatePath('xigg_main_shownodes.inc.html');
?>
<div class="nodesBreadcrumb">
  <?php echo $breadcrumb;?>
</div>
<div class="nodesHead clearfix">
  <ul>
    <li>
      <a href="<?php echo Sabai_URL::get('', array('category_id' => $requested_category_id, 'user_id' => $requested_user_id, 'keyword' => $requested_keyword));?>" title="<?php _e('Popular news');?>"><?php _h(sprintf(_('Popular news (%d)'), $popular_count));?></a>
    </li>
    <li class="active"><?php _e('Upcoming news');?></li>
    <?php if ($USER->isInRole(array(XIGG_ROLE_ADMIN, XIGG_ROLE_EDITOR, XIGG_ROLE_WRITER, XIGG_ROLE_SUBMITTER))):?>
    <li>
      <a href="<?php echo Sabai_URL::get('/submit');?>" title="<?php _e('Submit news');?>"><?php _e('Submit news');?></a>
    </li>
    <?php endif;?>
  </ul>
  <h1 class="categoryTitle"><?php _h($category_title);?></h1>
</div>
<div class="nodesFeed">
  <a href="<?php echo Sabai_URL::get('/rss/upcoming', array('category_id' => $requested_category_id, 'user_id' => $requested_user_id, 'keyword' => $requested_keyword));?>"><img src="<?php echo $LAYOUT_URL;?>/images/feed.png" width="16" height="16" alt="RSS feed" title="RSS feed" /></a>
</div>
<div class="nodesSearch">
  <form method="get" id="nodesSearchForm">
<?php _e('Search: ');?>
    <select name="category_id">
<?php     foreach ($category_list as $category_id => $category_name):?>
<?php       if ($category_id == $requested_category_id):?>
      <option value="<?php _h($category_id);?>" selected="selected"><?php _h($category_name);?></option>
<?php       else:?>
      <option value="<?php _h($category_id);?>"><?php _h($category_name);?></option>
<?php       endif;?>
<?php      endforeach;?>
    </select>
    <input name="keyword" type="text" value="<?php _h($requested_keyword);?>" size="15" />
    <input type="hidden" name="sort" value="<?php _h($requested_sort);?>" />
    <input type="submit" value="<?php _e('Search');?>" />
  </form>
</div>
<table class="nodesNav">
  <tr>
    <td class="nodesNavResults"><?php echo $node_nav_result;?></td>
    <td class="nodesNavSort"><?php _e('Sort by: '); select_to_remote('sort', $requested_sort, 'xigg-main-showupcomingnodes', $sorts, array('base' => '/node/upcoming', 'params' => array('category_id' => $requested_category_id, 'user_id' => $requested_user_id, 'keyword' => $requested_keyword)), _('GO'));?></td>
  </tr>
</table>
<?php if (isset($nodes)): $nodes =& $nodes->with('User'); $nodes =& $nodes->with('LastComment', 'User'); $nodes->rewind();?>
<table class="nodes" cellspacing="0">
  <thead>
    <tr>
      <th class="text"><?php _e('Title');?></th>
      <th><?php _e('Views');?></th>
      <th><?php _e('Votes');?></th>
      <th><?php _e('Replies');?></th>
      <th><?php _e('Published');?></th>
      <th class="text"><?php _e('Last reply');?></th>
    </tr>
  </thead>
  <tbody>
<?php   while ($e =& $nodes->getNext()):
          if ($e->isHidden()):?>
    <tr style="background-color:#eee;">
<?php     else:?>
    <tr>
<?php     endif;?>
      <td class="nodeInfoPoster text">
<?php     $node_user =& $e->get('User'); $node_user->printHTMLImageLink(32, 32);?>
<?php     if (!$e->get('allow_comments')):?><img src="<?php echo $LAYOUT_URL?>/images/tick.gif" alt="" /><?php endif;?>
<?php     if (!isset($category)) $category =& $e->get('Category');?>
<?php     if ($category) printf('<a href="%s">%s</a>: ', Sabai_URL::get('', array('category_id' => $category->getId())), h($category->getLabel()));?>
<?php     unset($category);?>
        <a href="<?php echo Sabai_URL::get('/node/' . $e->getId());?>"><?php _h($e->get('title'));?></a><br />
<?php     printf(_('%s posted <strong>%s</strong>'), $node_user->getHTMLLink(), h($this->helper('XiggAgo', $e->getTimeCreated())));?>
      </td>
      <td><?php echo number_format($e->get('views'));?></td>
      <td><?php echo $e->getVoteCount();?></td>
      <td><?php echo $e->getCommentCount();?></td>
      <td><?php if ($e->isPublished()) _h($this->helper('XiggAgo', $e->get('published')));?></td>
      <td class="nodeInfoPoster text">
<?php     if ($last_comment =& $e->get('LastComment')):?>
<?php       if ($last_user =& $last_comment->get('User')) $last_user->printHTMLImageLink(32, 32);?><a href="<?php echo Sabai_URL::get('/node/' . $e->getId(), array('comment_id' => $last_comment->getId()), 'comment' . $last_comment->getId());?>"><?php _h($last_comment->getLabel());?></a><br />
<?php       printf(_('%s posted <strong>%s</strong>'), $last_user->getHTMLLink(), h($this->helper('XiggAgo', $last_comment->getTimeCreated())));?>
<?php     endif;?>
      </td>
    </tr>
<?php   endwhile; ?>
  </tbody>
</table>
<table class="nodesNav">
  <tr>
    <td class="nodesNavPages"><?php echo $this->helper('PageNavRemote', 'xigg-main-showupcomingnodes', $pages, $page->getPageNumber(), array('base' => '/node/upcoming', 'params' => array('category_id' => $requested_category_id, 'user_id' => $requested_user_id, 'keyword' => $requested_keyword, 'sort' => $requested_sort)));?></td>
  </tr>
</table>
<?php endif;?>
<script type="text/javascript">
Event.observe('nodesSearchForm', 'submit', function(evt) {
  new Ajax.Updater(
	'xigg-main-showupcomingnodes',
    '<?php echo Sabai_URL::get('/node/upcoming', array('sort' => $requested_sort));?>',
    {
      evalScripts: true,
      method: 'get',
      parameters: evt.element().serialize() + '&<?php echo SABAI_REQUEST_WEB_PARTIAL_PARAM;?>=1'
    }
  );
  Event.stop(evt);
});
</script>